﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using AfterCaveStory.Utils;

namespace AfterCaveStory.Core.Scenes
{

    class Level1 : SceneBase
    {
        private World world;
        private Personagem personagem;
        Pause pause;

        public override void start()
        {
            world = new World(0.5f);
            
            this.pause = new Pause();

            personagem = new Personagem(Game1.Self.Content.Load<Texture2D>("personagens"), new Rectangle(0, 0, 32, 32), 0.2f);
            personagem.isStatic = false;
            personagem.drawCollisionBounds = false;
            personagem.setarPontoDeReferencia(Objeto2D.PontoDeReferencia.CENTRO);
            personagem.x = 300;
            personagem.y = 300;
            world.createObject(personagem);

            world.Map = txtToList.loadTxt("../../../../AfterCaveStoryContent/mapa1.txt");


        }

        public override void update(GameTime gameTime)
        {
            if (!pause.pausado)
            {

                world.update();
                world.camera.Pos = Vector2.Lerp(world.camera.Pos, new Vector2(personagem.x, personagem.y), 0.1f);

                if (Mouse.GetState().LeftButton == ButtonState.Pressed)
                {
                    world.camera.Zoom += 0.01f;
                }
                else if (Mouse.GetState().RightButton == ButtonState.Pressed)
                {
                    world.camera.Zoom -= 0.01f;
                }

                if (Controller.KeyPressed(Keys.P))
                {
                    pause.pausado = true;
                }
            }
            else
            {
                pause.update(gameTime);
            }

        }

        public override void draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            world.draw(gameTime, spriteBatch);
            pause.draw(gameTime, spriteBatch);
        }

        public override void terminate()
        {

        }
       
    }
}
